package com.cndw.kungfu.model.pvp.war;

import java.util.concurrent.ScheduledFuture;

import com.cndw.kungfu.ext.LogUtil;
import com.cndw.kungfu.ext.TimeProcesser;
import com.cndw.kungfu.model.Context;

public class WarPross implements Runnable {

	private static ScheduledFuture<?> task;

	@Override
	public void run() {
		try {
			WarData.getInstance().runBoss();
			if (WarData.getInstance().getStep() >= 3 && task!= null) {
				task.cancel(false);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public synchronized static void runBoss() {
		WarData.getInstance().checkCycle();
		if (WarData.getInstance().getStep() >= 3) {
			return ;
		}
		if (task != null) {
			LogUtil.getMain().error("war task err init ");
			return;
		}
		int currentTime = TimeProcesser.getUnixTime();
		int diff = WarConfig.getSingleBegin() + WarConfig.eliminateBegin - currentTime;
		WarPross warPross = new WarPross();

		task = Context.getTimerServer().scheduleAtFixedRate(warPross, diff, 10);
		LogUtil.getMain().debug("war begin " + diff);

	}

}
